//
//  ByChaseNumberVC.m
//  caipiao_ios
//
//  Created by mc on 2018/8/13.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByChaseNumberVC.h"
#import "ByChaseNumberTitleCell.h"
#import "ByChaseNumberDetailCell.h"

#import "ByChaseNumberPromptCell.h"

@interface ByChaseNumberVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) ByNetModel *detailModel;


@end

@implementation ByChaseNumberVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self addLeftBackBarButtonItem];
    self.title = @"追号详情";
    

    
    [self loadData];
    
}
- (void)loadData{
    
    ByNetModel *netModel = [[ByNetModel alloc] init];
    netModel.ID  = self.netModel.ID;
    [ByCoreToolAlert showLoadind:@"加载中"];
    [ByApiOther chasingInfo:netModel success:^(ByNetBaseResult *result) {
        [ByCoreToolAlert hideHud];
        SLog(@"追号详情 = %@", result.data);
        [self initViews];
        self.detailModel = [[ByNetModel alloc] initContentWithDic:result.data[@"data"]];
        NSArray *betAry = result.data[@"data"][@"bet"];
        
        if ([betAry isKindOfClass:[NSArray class]] && betAry.count > 0) {
            self.detailModel.bet_playtype = @"混合投注";
        }else{
            self.detailModel.bet_playtype = result.data[@"data"][@"bet"][@"playtype"];
        }
        
        [self.tableView reloadData];
        
    } failure:^(ByNetBaseResult *result) {
        [ByCoreToolAlert showFailureWithText:result.msg];
    }];
}

- (void)initViews{
    
    self.view.backgroundColor = BY_BACKGROUND_COLOR;
    self.tableView = [[UITableView alloc] init];
    self.tableView.backgroundColor = BY_BACKGROUND_COLOR;
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(0);
        make.right.equalTo(self.view).offset(0);
        if (@available(ios 11.0,*)) {
            make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop).offset(0);
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(0);
        } else {
            make.top.equalTo(self.view).offset(0);
            make.bottom.equalTo(self.view).offset(0);
        }
    }];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
        ByChaseNumberTitleCell *cell = [ByChaseNumberTitleCell cellWithTableView:tableView];
        cell.netModel = self.detailModel;
        return cell;
    }else if (indexPath.row == 1){
        ByChaseNumberDetailCell *cell = [ByChaseNumberDetailCell cellWithTableView:tableView];
        cell.netModel = self.detailModel;
        return cell;
    }
    
    
    
    ByChaseNumberPromptCell *cell = [ByChaseNumberPromptCell cellWithTableView:tableView];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return 185;
    }else if (indexPath.row == 1){
        return 50 + 41 * 2;
    }else{
        return 120;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
